package cn.sciento.core.jackson.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ObjectMapperConfiguration {
    @Bean
    public ObjectMapperPostProcess objectMapperPostProcess() {
        return new ObjectMapperPostProcess();
    }

    @Bean
    @ConditionalOnBean({ObjectMapperPostProcess.class})
    @ConditionalOnMissingBean({ObjectMapper.class})
    public ObjectMapper objectMapper(ObjectMapperPostProcess objectMapperPostProcess) {
        ObjectMapper mapper = new ObjectMapper();
        objectMapperPostProcess.postProcessAfterInitialization(mapper, "objectMapper");
        return mapper;
    }
}
